-
Notifications
You must be signed in to change notification settings - Fork 16
Feat/kurganov shared memory #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CyprienBosserelle
wants to merge
38
commits into
development
Choose a base branch
from
feat/kurganov-shared-memory
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…to enhance their performance. Here's a summary of the changes: I've optimized six CUDA device functions: - updateKurgXGPU - updateKurgYGPU - updateKurgXATMGPU - updateKurgYATMGPU - AddSlopeSourceXGPU - AddSlopeSourceYGPU The main idea was to use a faster type of memory called shared memory. Here’s how I approached it: 1. I looked for parts of the code where a thread needs data from its neighbors. 2. For these parts, I set up shared memory to hold the data temporarily (e.g., for `XEv.h`, `XEv.zs`, `XGrad.dhdx`, `Patm`, `XFlux.Fqux`, etc.). 3. At the beginning of each kernel, I copied the necessary data from the main global memory into these shared memory areas, including any extra data needed for calculations involving neighbors. 4. I used a synchronization command (`__syncthreads()`) to make sure all data was loaded into shared memory before any calculations began, and also before writing any updated shared data back to the main memory. 5. I updated the calculations to use the data in shared memory instead of directly accessing global memory. 6. Finally, where needed, I copied the results from shared memory back to global memory (for example, with the flux arrays in the `AddSlopeSource*` kernels). I used some predefined constants (`STATIC_MAX_BLOCK_X = 16`, `STATIC_MAX_BLOCK_Y = 16`, `SHARED_MEM_HALO_WIDTH = 1`) to set the size of the shared memory arrays. I also added some checks to prevent errors if the way the kernels are launched doesn't quite match these predefined sizes. The logic for handling boundaries between different blocks of data (like when blocks have different levels of detail) still uses direct access to global memory. These optimizations apply to both single and double-precision versions of the kernels. The goal is to reduce the time spent waiting for data from global memory, which should make the kernels run faster.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Test Jules coding assistant in optimising using shared memory